package edu.tgc.entity.system;

import java.util.HashSet;
import java.util.Set;
import java.util.UUID;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import com.fasterxml.jackson.annotation.JsonIgnore;

@Entity
@Table(indexes = { @Index(columnList = "codePath asc", unique = true), @Index(columnList = "sort asc"), @Index(columnList = "enabled asc") })
public class SysDuty extends BaseAuditableDateEntity {

    private static final long serialVersionUID = 6797725857127400519L;

    @JsonIgnore
    protected Set<SysDuty> childrens;
    protected String code;
    protected String codePath;
    protected String description;
    protected Boolean enabled = true;
    protected String name;
    @JsonIgnore
    protected SysDuty parent;
    @JsonIgnore
    protected Set<SysPosition> positions = new HashSet<>();
    protected Integer sort = 1;
    protected SysType type;

    public SysDuty() {
    }

    public SysDuty(UUID id) {
        this.id = id;
    }

    @OneToMany(mappedBy = "parent")
    public Set<SysDuty> getChildrens() {
        return this.childrens;
    }

    @Column(length = 31)
    public String getCode() {
        return this.code;
    }

    @Column(length = 255)
    public String getCodePath() {
        return this.codePath;
    }

    @Column(name = "description", length = 255)
    public String getDescription() {
        return this.description;
    }

    @Column(name = "enabled")
    public Boolean getEnabled() {
        return this.enabled;
    }

    @Column(name = "name", length = 31)
    public String getName() {
        return this.name;
    }

    @ManyToOne
    @JoinColumn(name = "parent_id")
    public SysDuty getParent() {
        return this.parent;
    }

    @ManyToMany
    @JoinTable(name = "sys_position_duty", joinColumns = @JoinColumn(name = "duty_id"), inverseJoinColumns = @JoinColumn(name = "position_id"))
    public Set<SysPosition> getPositions() {
        return this.positions;
    }

    @Column(name = "sort")
    public Integer getSort() {
        return this.sort;
    }

    @ManyToOne
    @JoinColumn(name = "type_id")
    public SysType getType() {
        return this.type;
    }

    public void setChildrens(Set<SysDuty> childrens) {
        this.childrens = childrens;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public void setCodePath(String codePath) {
        this.codePath = codePath;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public void setEnabled(Boolean enabled) {
        this.enabled = enabled;
    }

    public void setName(String name) {
        this.name = name;
    }

    public void setParent(SysDuty parent) {
        this.parent = parent;
    }

    public void setPositions(Set<SysPosition> positions) {
        this.positions = positions;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    public void setType(SysType type) {
        this.type = type;
    }
}
